<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['admin'])) {
header('Location: login.php');
}

$dbhandle= new PDO('sqlite:./datos/galeria.sqlite');

$result= $dbhandle->query("SELECT Imagen FROM Pinturas WHERE Id='".$_GET['id']."'");

$row = $result->fetch();

unlink('upload'.$row[0]);

unlink('upload/defaultSize'.$row[0]);

unlink('upload/doubleHeight'.$row[0]);

unlink('upload/doubleSize'.$row[0]);


$sql = 	"DELETE FROM Pinturas WHERE Id = ?";
$q = $dbhandle->prepare($sql);
$q->execute(array($_GET['id']));

$sql = 	"DELETE FROM Etiquetas WHERE PId = ?";
$q = $dbhandle->prepare($sql);
$q->execute(array($_GET['id']));

$dbhandle = NULL;

header('Location: index.php');
?>